<?php /*a:2:{s:69:"D:\phpstudy_pro\WWW\www.xnadmin.site\app\admin\view\data_pic\add.html";i:1612148019;s:63:"D:\phpstudy_pro\WWW\www.xnadmin.site\app\admin\view\iframe.html";i:1588058566;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo xn_cfg('base.sys_name'); ?></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script>
        //全局上传文件端口
        var UPLOAD_FILE_URL = "<?php echo url('upload_files/upload'); ?>";
        //全局选择文件端口
        var SELECT_FILE_URL = "<?php echo url('upload_files/select'); ?>";
    </script>
    <script src="/static/admin/js/jquery-2.0.0.min.js"></script>
    <script src="/static/admin/js/common.js"></script>
    <script src="/static/admin/js/upload.js"></script>
    <script src="/static/admin/js/webuploader.min.js"></script>
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/base.css" media="all">
    
    <style>
        .h15{height: 15px;}
    </style>
</head>
<body>
<div class="h15"></div>

<style>
    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
    }
</style>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form>
        <div class="layui-form-item">
            <label class="layui-form-label">行业类型</label>
            <div class="layui-input-inline">
                <select name="parent_typeid" lay-filter="parent_typeid" id="parent_typeid">
                    <option value="0">请选择</option>
                    <?php if(is_array($parent_typelist) || $parent_typelist instanceof \think\Collection || $parent_typelist instanceof \think\Paginator): if( count($parent_typelist)==0 ) : echo "" ;else: foreach($parent_typelist as $key=>$vo): ?>
                    <option value="<?php echo htmlentities($vo['id']); ?>" <?php if($data['parent_typeid'] == $vo['id']): ?>selected<?php endif; ?> ><?php echo htmlentities($vo['title']); ?></option>
                    <?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="typeid" id="typeid">
                    <option value="0">请选择</option>
                    <?php if(is_array($typelist) || $typelist instanceof \think\Collection || $typelist instanceof \think\Paginator): if( count($typelist)==0 ) : echo "" ;else: foreach($typelist as $key=>$vo): ?>
                    <option value="<?php echo htmlentities($vo['id']); ?>" <?php if($data['typeid'] == $vo['id']): ?>selected<?php endif; ?> ><?php echo htmlentities($vo['title']); ?></option>
                    <?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属项目</label>
            <div class="layui-input-block layui-form-select">
                <input type="text" name="project" placeholder="" autocomplete="off" class="layui-input" value="<?php echo htmlentities($data['project']); ?>" id="project">
                <dl class="layui-anim layui-anim-upbit" id="projectList">
                </dl>
            </div>
        </div>
        
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test2">多图片上传</button>
                <input class="layui-upload-file" type="file" accept="" name="file" multiple=""> 
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                  预览图：
                  <div class="layui-upload-list" id="demo2"></div>
               </blockquote>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submit">保存</button>
                <button type="button" id="uploads" style="display: none;"></button>
            </div>
        </div>
    </form>
</div>


<script src="/static/admin/layui/layui.all.js"></script>
<script src="/static/admin/js/admin.js"></script>

<script>
    var form = layui.form;
    form.on('select(parent_typeid)', function(res) { 
        $("#typeid").empty();
        if(res.value != 0){
            $.get("<?php echo url('admin/DataType/getSonType'); ?>?pid="+res.value,function(result){
                if(result.status){
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#typeid").append(new Option(item.title,item.id));
                    });
                    form.render("select");
                }
            });
        }else{
            $("#typeid").append(new Option('请选择',0));
            form.render("select");
        }
    })

    layui.use('upload', function(){
        var $ = layui.jquery,
        upload = layui.upload;
        upload.render({
            elem: '#test2'
            ,url: '<?php echo request()->url(); ?>' //改成您自己的上传接口
            ,auto: false //选择文件后不自动上传
            ,multiple: true
            ,accept: 'images'
            ,acceptMime: "image/*"
            ,exts: 'png|jpg|bmp' 
            ,size: 5000 
            ,field: 'pic'
            ,bindAction: '#uploads'
            ,data: {
                parent_typeid: function () {
                    return $("#parent_typeid").val();
                },
                typeid: function () {
                    return $("#typeid").val();
                },
                project: function () {
                    return $("#project").val();
                }
            }
            ,choose: function(obj){
                //FILES = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img id="'+index+'" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,done: function(res, index, upload){
                //上传完毕
                if(res.status){
                    $('#'+index).css('opacity','0.4');
                }
                //delete FILES[index]; //删除队列
            }
            ,allDone: function(obj){
                //当文件全部被提交后，才触发
                layer.msg('全部执行完毕', {
                time: 1500 
                }, function(){
                    window.parent.location.reload();
                }); 
            }
            ,error: function(res){
                console.log(res);
            }
        });
   }); 

   $(function(){
       $('#project').keyup(function(event){
            var word = $("#project").val().trim();
            if(word.length>0){
                $.get("<?php echo url('admin/DataProject/getProjectByLike'); ?>",{word:word},function(res){
                    if(res.status){
                        var html = '';
                        $.each(res.data,function(index,obj){
                            html += '<dd data-tid="'+obj.typeid+'" data-ptid="'+obj.parent_typeid+'">'+obj.title+'</dd>';
                        });
                        $('#projectList').html(html).css('display','block');
                    }else{
                        $('#projectList').html('').css('display','none');
                    }
                });
            }else{
                $('#projectList').html('').css('display','none');
            }
       });

       $('#projectList').on('click','dd',function(){
           var ptid = $(this).attr('data-ptid');
           var tid = $(this).attr('data-tid');

           $('#project').val($(this).text());
           $('#projectList').html('').css('display','none');
           
           var dd = $('#parent_typeid').next().find('dl dd[lay-value='+ptid+']');
           dd.click();

            $.get("<?php echo url('admin/DataType/getSonType'); ?>?pid="+ptid,function(result){
                if(result.status){
                    $("#typeid").empty();
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        if(tid == item.id){
                            $("#typeid").append(new Option(item.title,item.id,false,true));
                        }else{
                            $("#typeid").append(new Option(item.title,item.id));
                        }
                    });
                    form.render("select");
                }
            });
           
       });
       $('#project').click(function(){
            if( $("#projectList").children().length ){
                $("#projectList").toggle();
            }
       });

       $('#submit').click(function(){
            var word = $("#project").val().trim();
            if(word.length>0){
                $.get("<?php echo url('admin/DataProject/getProjectByName'); ?>",{word:word},function(res){
                    if(res.status){
                        $('#uploads').click();
                    }else{
                        layer.msg('此项目不存在',{time:1500,icon:2});
                    }
                });
            }else{
                $('#uploads').click();
            }
       });
   });
</script>

</body>
</html>